import { getDefaultFields } from '../utils';

module.exports = app => {
	const DataTypes = app.Sequelize;

	const Model = app.model.define('order_goods', {
		id: {
			type: DataTypes.INTEGER(8).UNSIGNED,
			allowNull: false,
			primaryKey: true,
			autoIncrement: true
		},
		order_id: {
			type: DataTypes.STRING(100),
			allowNull: false,
			defaultValue: '0'
		},
		goods_id: {
			type: DataTypes.INTEGER(8).UNSIGNED,
			allowNull: false,
			defaultValue: '0'
		},
		goods_name: {
			type: DataTypes.STRING(120),
			allowNull: false,
			defaultValue: ''
		},
		product_id: {
			type: DataTypes.INTEGER(8).UNSIGNED,
			allowNull: true,
			defaultValue: '0'
		},
		number: {
			type: DataTypes.INTEGER(5).UNSIGNED,
			allowNull: false,
		},
		price: {
			type: DataTypes.INTEGER(11),
			allowNull: false,
			comment: '销售价格'
		},
		brief: {
			type: DataTypes.STRING(500),
			allowNull: false,
			defaultValue: '',
			comment: '简介'
		},
		market_price: {
			type: DataTypes.INTEGER(11),
			allowNull: false,
			comment: '市场价'
		},
		is_real: {
			type: DataTypes.INTEGER(1).UNSIGNED,
			allowNull: true,
			defaultValue: '0'
		},
		// 属性组合ids
		goods_compose_ids: {
			type: DataTypes.STRING(255),
			allowNull: true,
		},
		// 属性组合names
		goods_compose_names: {
			type: DataTypes.STRING(255),
			allowNull: true,
		},
		main_pic: {
			type: DataTypes.STRING(255),
			allowNull: false,
		},
		...getDefaultFields()
	}, {
		tableName: 'order_goods',
		timestamps: false
	});


	Model.sync({ alter: true });

	Model.associate = function () {
	}

	return Model;
};
